package com.haha.qqchannelbot.config;

import com.haha.qqchannelbot.entity.Bot;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@Log4j2
public class BotConfig {

    @Value("${bot.app_id}")
    private String appId;

    @Value("${bot.app_key}")
    private String appKey;

    @Value("${bot.base_url}")
    private String baseUrl;

    @Value("${bot.ws_url}")
    private String wsUrl;

    @Value("${bot.current_shared:0}")
    private Integer currentShared;

    @Value("${bot.count_shared:1}")
    private Integer countShared;

    @Value("${bot.reconnect_interval:5000}")
    private Integer reconnectInterval;

    @Value("${bot.reconnect_max:5}")
    private Integer reconnectMax;



    @Bean("bot")
    public Bot initBotInfo() {
        String token = "Bot " + appId + "." + appKey;
        Bot bot = new Bot(appId, appKey, baseUrl, token);
        bot.setWsUrl(wsUrl);
        bot.setCurrentShared(currentShared);
        bot.setCountShared(countShared);
        bot.setReconnectInterval(reconnectInterval);
        bot.setReconnectMax(reconnectMax);
        return bot;
    }

}
